package org.sjsu.freedoor.model;

import org.json.JSONException;
import org.json.JSONObject;
import org.sjsu.freedoor.util.Utilities;

public class Offer {
	private String m_email;
	private String m_message;
	private String m_id;
	
	public Offer() {
		
	}
	
	public Offer(String email, String message, String id) {
		m_email = email;
		m_message = message;
		m_id = id;
	}
	
	public boolean loadOffer(JSONObject jsonObj) {
		try {
			m_email = jsonObj.getString("email");
			m_message = jsonObj.getString("message");
			m_id = jsonObj.getString("id");
		} catch (JSONException e) {
			System.out.println("Invalid Offer jsonObj: " + jsonObj.toString());
			return false;
		}
		return true;
	}
	
	public boolean loadOffer(String jsonString) {
		try {
			JSONObject obj = new JSONObject(jsonString);
			
			return loadOffer(obj);
		} catch (JSONException e) {
			System.out.println("Invalid Offer jsonString: " + jsonString);
			return false;
		}
	}
	
	public void setEmail(String email) {
		m_email = email;
	}
	
	public String getEmail() {
		return m_email;
	}
	
	public void setMessage(String msg) {
		m_message = msg;
	}
	
	public String getMessage() {
		return m_message;
	}
	
	public void setId(String id) {
		m_id = id;
	}
	
	public String getId() {
		return m_id;
	}
	
	public String toJsonString() {
		String ret  = "{\"email\":\"" + m_email + "\", \"message\":\"" + m_message + "\", \"id\":\"" + m_id + "\"}";
		return ret;
	}
	
	public JSONObject toJsonObject()
	{
		return Utilities.toJsonObject(this.toJsonString());
	}
}
